#pragma once

#include "MBPlane.h"
#include "MBVec3.h"

/**
  *	An MBTriangleSightFrustum is the view frustum that is defined by the camera
  * position and the three vertexes of one particular triangle of the model.
  * When connecting all these points with each other, a morphed triangular
  * pyramid is the result. This volume is defined as triangle sight frustum. 
  */
class MBTriangleSightFrustum
{
public:
	MBTriangleSightFrustum( const MBVec3 *trianglePoints, const MBVec3 &cameraPosition );
	bool IsIntersectingWithAxisAlignedBox( const MBVec3 &boxMin, const MBVec3 &boxMax ) const;
	bool IsIntersectingWithTriangle( const MBVec3 *triangle_points ) const;
	bool IsPointInside( const MBVec3 &point ) const;
private:

	/**
	  * Enum value specifying the desired plane of the frustum. Order of the
	  * indices belongs to a CCW order when looked at from the inside of the
	  * frustum.
	  */
	enum MBPlaneIndex {
		P1_P0_CAMPOS = 0,
		P2_P1_CAMPOS = 1,
		P0_P2_CAMPOS = 2,
		P0_P1_P2 = 3
	};

	/** The four planes defining the triangle sight frustum */
	MBPlane mPlanes[4];
	/** Point P0 of the triangle. Must be the "left" neighbor of P2 */
	MBVec3 mP0;
	/** Point P1 of the triangle. Must be the "left" neighbor of P0 */
	MBVec3 mP1;
	/** Point P2 of the triangle. Must be the "left" neighbor of P1 */
	MBVec3 mP2;
	/** Position of the camera */
	MBVec3 mCamPos;
};